
/*******************密码修改start*****************************/

var myApp=angular.module('myApp',[]);
myApp.controller('controller',function($scope,$interval){
    $scope.password2=' ';
    $scope.code = '';
    $scope.canClick=false;//发送验证码按钮可以点击
    $scope.description='发送验证码';
    var second=59;
    var timerHandler;
    $scope.getTestCode=function(){

        var url =server + '/server/users/request/captcha2.json';
        $.get(url, function (data) {
            if (data.code == 12000) {
                alert("登录超时");
                window.location.replace('../login.html');
            }
        });

        timerHandler=$interval(function(){
            timer();
        },1000);
        function timer(){
            if(second<0){
                $interval.cancel(timerHandler);
                second=59;
                $scope.canClick=false;
                $scope.description='发送验证码';
            }
            else
            {
                $scope.description=second+'后重发';
                second--;
                $scope.canClick=true;//发送验证码按钮不可点击
            }
        }
    }
});

$('#next').click(function(){
    var new_password= $(document.myForm.password2);
    var sure_password= $(document.myForm.password3);
    if(new_password.val()!==sure_password.val()){
        alert('两次密码输入不一致');
        new_password.focus();
        new_password.select();
        return false;
    }
    else{
        var url=window.location.href;
        if(url.indexOf('/page/')==-1){//条件判断首页密码修改还是page里面的密码修改
            var name = $(document.myForm.name).val();
            var code = hex_md5($(document.myForm.password2).val());
            var url0 = server + '/server/users/setPassword.json';
            var args = {"username":name,"password":code};
            $.post(url0, args, function (data) {});
            window.location.assign('page/index.html');
        }

        else{
            var md5 = $(document.myForm.password).val();
            var code2 = hex_md5($(document.myForm.password3).val());
            var url2 = server + '/server/users/updatePassword.json';
            var args2 = {"md5":md5,"newPassword":code2};
            $.post(url2, args2, function (data) {});
            window.location.assign('modify-password-success.html');
        }

    }
});



//
//$('#next').click(function(){
//    var old_password= $(document.myForm.code);
//    var new_password= $(document.myForm.password2);
//    var sure_password= $(document.myForm.password3);
//    if(old_password.val()===new_password.val()){
//        alert('新旧密码不能一样');
//        new_password.focus();
//        return false;
//    }
//    else if(new_password.val()!==sure_password.val()){
//        alert('两次密码输入不一致');
//        sure_password.focus();
//        return false;
//    }
//    else{
//        var url=window.location.href;
//        if(url.indexOf('/page/')==-1){//条件判断首页密码修改还是page里面的密码修改
//            var name = $(document.myForm.name).val();
//            var code = hex_md5($(document.myForm.password2).val());
//            var url0 = server + '/server/users/setPassword.json';
//            var args = {"username":name,"password":code};
//            $.post(url0, args, function (data) {});
//            window.location.assign('page/index.html');
//        }
//        else{
//            window.location.assign('modify-password-success.html');
//        }
//
//    }
//});
/*******************密码修改end*****************************/